<template>
	<view class="list">
	<!-- 	<view class="skxi" v-if="flag">
			<view class="con">
				<image src="../../static/images/icon/jingtan.png"></image>
				<view class="tip">
					<view>没收到款千万不要确认</view>
					<view>造成损失自己负责</view>
				</view>
				<view class="jine">
					<input type="number" v-model="amount" placeholder="输入收款金额" />
				</view>
				<view class="confim">

					<view @click="quxiao">取消</view>
					<view class="blue" @tap="tijiao">确定</view>
				</view>
			</view>
		</view> -->
		<view class="item" v-for="(item,index) in orderunderway" :key="index">
			<view class="top"  @tap="slide(index)">
				<view class="left">
					<image :src="item['logo_url']"></image>
				</view>
				<view class="middle">
					<view class="tit">{{item['order_amount']}}</view>
					<view>订单流水号 {{item['transaction_id']}}</view>
					<view>商户号 {{item['order_no']}}</view>
				</view>
				<view class="right">
					<image mode="widthFix" v-if="tabindex == index"  src="../../static/images/icon/shang.png"></image>
					<image mode="widthFix" v-else src="../../static/images/icon/xia.png"></image>
				</view>
			</view>
			<view class="bottom" v-if="tabindex == index">
				<view class="title">
					当前接单账号：
					<text>{{item['account']}}</text>
				</view>
				<view class="xinxi">
					<view>账户类型：{{item['ploat_name']}}</view>
					<view>账号：{{item['account']}}</view>
					<view>昵称：{{item['nickname']}}</view>
					<view>订单创建时间：{{item['create_time']}}</view>
				</view>
				<view class="shoukuan">
					<text class="tip">收到款后请及时点击【确认收款】按钮</text>
					<view class="time">
						<text>剩余时间：</text>
						<tui-countdown :time="formatDate(item['take_time'],item['order_id'])" @end="endOfTime(item)" :height="30" :width="30" :size="26" :colonsize="32" color="#fff" bcolor="#e41f19"
						 bgcolor="#e41f19" coloncolor="#e41f19"></tui-countdown>
					</view>
					<view class="queren" @click="shou(item)">
						确认收款
					</view>
				</view>
			</view>

		</view>
		<view class="wu" v-if="orderunderway.length==0">
			暂无数据
		</view>
	</view>


</template>
<script>
	import {
		mapState
	} from 'vuex';
	import moment from "moment"
	import tuiIcon from "@/components/icon/icon"
	import tuiCountdown from "@/components/countdown/countdown"
	export default {
		data() {
			return {
				flag: false,
				tabindex: -1,
				account: '',
				amount: '',
				timeList: [{
					hours: 1,
					minute: 40,
					second: 17
				}, {
					hours: 2,
					minute: 20,
					second: 58
				}, {
					minute: 19,
					second: 36
				}, {
					second: 20
				}]
			}
		},
		components: {
			tuiIcon,
			tuiCountdown
		},
		props: {
			current: {
				type: Number,
				default: 0
			}
		},
		methods: {
			quxiao(){
				this.flag = false;
				this.amount ="";
				
			},
			endOfTime: function(item) {
				var data = {
					token: uni.getStorageSync('token'),
					order_id:item.order_id
				};
				this.$store.dispatch('ordertimeout', data)
				.then(res=>{
					if(res.data.code==1){
						var data = {
							token: uni.getStorageSync('token'),
						};
						this.$store.dispatch('orderunderway', data);
					}
				})
				
			},
			shou(item) {
				var data={
					flag:true,
					account:item
				}
				this.flag = true;
				this.account = item;
				this.$bus.$emit("shou",data)
				
			},
			slide(item) {
				if (this.tabindex == item) {
					this.tabindex = -1;
				} else {
					this.tabindex = item;
				}
				
			},
			choashi(item){
					var data = {
					token: uni.getStorageSync('token'),
					order_id:item
				};
				this.$store.dispatch('ordertimeout', data)
				.then(res=>{
					if(res.data.code==1){
						var data = {
							token: uni.getStorageSync('token'),
						};
						this.$store.dispatch('orderunderway', data);
					}
				})
			},
			tijiao() {
				if (this.amount) {
					var data = {
						token: uni.getStorageSync('token'),
						order_id:this.account.order_id,
						order_amount:this.amount
					}
					this.$store.dispatch('confirmreceitp', data)
					.then(res=>{
						this.amount = "";
						uni.showToast({
							title: res.data.msg,
							icon: "none"
						})
						if(res.data.code==1){
							var data = {
								token: uni.getStorageSync('token'),
							};
							this.$store.dispatch('orderunderway', data)
							this.flag = false;
						}
					})
				}
				else{
					uni.showToast({
						title: '请输入收款金额',
						icon: "none"
					})
				}
			}
		},
		watch: {
			current(newName, oldName) {
				if (newName == 1) {
					var data = {
						token: uni.getStorageSync('token'),
					};
					this.$store.dispatch('orderunderway', data);
					this.tabindex= -1;
				}
			},

		},
			computed: {
			...mapState([
				"orderunderway",
				"userinfo"
			]),
			formatDate() {
				return function(i,n){
					var h = (moment(i).unix()+ this.userinfo.time_interval*1) - moment().unix();
					var s={};
					if(h>0){
						 var hour = Math.floor( h/ 300); 
                          var minute = Math.floor( (h -  - hour*300) /60 ); 
                         var second = h  - hour*300 - minute*60;
						s={
							hours: hour,
							minute: minute,
							second: second
						};
					}
					else{
						this.choashi(n);
						s={
							hours: 0,
							minute: 0,
							second: 0
						};
					}
				return s;
				};
			},
		},
	}
</script>

<style lang="scss" scoped src="./index.scss"></style>
